import axios from "axios"

// 创建一个实例，防止污染全局对象
export const request = axios.create({
  baseURL: "https://conduit.productionready.io"
})

export default ({store}) => {
  // 拦截器
  request.interceptors.request.use(function (config) {
    const { user } = store.state
    if(user && user.token){
      config.headers.Authorization = `Token ${user.token}`
    }
    // 返回config
    return config;
  }, function (error) {
    // 请求失败
    return Promise.reject(error);
  });
}
